#ifndef SBOTPLUGIN_H
#define SBOTPLUGIN_H

#include "SbotDef.h"

#include <QCoreApplication>
#include <QDebug>
#include <QIcon>
#include <QMutex>
#include <QObject>
#include <QQmlComponent>
#include <QQmlContext>
#include <QQmlEngine>
#include <QString>
#include <QThread>
#include <QWaitCondition>

class SbotPluginInformation {
  public:
    QString pluginName;     //插件名
    QString pluginVersion;  //插件版本号
    QString pluginQmlRes;   //插件qml资源url
    QIcon pluginLogo;       //插件Logo对象
};

// class SbotPluginState {};

class SbotPlugin : public QThread {
  private:
    QMutex threadMutex;
    QWaitCondition threadCondition;

  public:
    QQmlComponent* pluginUi = nullptr;
    QObject* qmlObj = nullptr;
    bool isPaused;
    bool isStopped = true;

  public:
    SbotPluginInformation pluginInfo;

  protected:
    void run() override;

  public:
    virtual ~SbotPlugin() = default;
    virtual void PluginInitAtThreadHook() = 0;  //线程级别初始化
    // virtual void PluginInitAtQmlHook() = 0;     // QML级别初始化
    virtual int PluginThreadLoop() = 0;  //线程

    int PluginQmlInit(QQmlEngine* engine);         //初始化插件qml对象
    QObject* GetQmlObject();                       //获取qml对象
    int PluginThreadStart();                       //启动插件线程
    int PluginThreadStop();                        //退出插件线程
    int PluginThreadPause();                       //挂起插件线程
    int PluginThreadResume();                      //恢复插件线程
    const SbotPluginInformation& GetPluginInfo();  //获取插件信息
};

QT_BEGIN_NAMESPACE
#define SbotPlugin_iid "org.SBOT.SbotPluginInterface"
Q_DECLARE_INTERFACE(SbotPlugin, SbotPlugin_iid)
QT_END_NAMESPACE

#endif
